package com.sjqi.demo;

import com.sjqi.demo.builer.SqlSessionFactoryBuilder;
import com.sjqi.demo.factory.SqlSessionFactory;
import com.sjqi.demo.io.Resources;
import com.sjqi.demo.po.InvoiceEntity;
import com.sjqi.demo.sqlsession.SqlSession;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;
import java.util.HashMap;
import java.util.List;

/**
 * @author qishaojun
 * 采用面向对象的方式仿写Mybatis框架
 */
public class MybatisV3 {
    private SqlSessionFactory sqlSessionFactory;

    @Before
    public void before() {
        String location = "mybatis/mybatis.xml";
        //字节流或者字符流
        InputStream inputStream = null;
        inputStream = Resources.gerResourcesAsStream(location);
        //私人订制  工厂是批量
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    }

    @Test
    public void test() {
        SqlSession sqlSession = sqlSessionFactory.openSqlSession();
        //TODO:这里如何改造成代理模式去做
        List<InvoiceEntity> list = sqlSession.selectList("", new HashMap<>());
        System.out.println(list);
    }
}
